﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeBehind="VoterCard.aspx.cs"
    Inherits="CivilRegistry.VoterCard" %>

<%@ Register Src="~/UserControls/UCUserGadget.ascx" TagName="UserGadget" TagPrefix="UC" %>
<%@ Register Src="~/UserControls/UCAddress.ascx" TagName="AddressControl" TagPrefix="UC" %>
<asp:Content ID="headerContent" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        function ReasonVisible(actionName) {
            if ($('#<%=btnDeactivate.ClientID%>').val() == "Deactivate") {
                if ($('#<%=lblReason.ClientID%>').css('visibility') == 'hidden') {
                    $('#<%=lblReason.ClientID%>').css('visibility', 'visible');
                    $('#<%=txtReason.ClientID%>').css('visibility', 'visible');
                    return false;
                }
                else if ($('#<%=txtReason.ClientID%>').val() == '') {
                    $('#<%=lblReasonValidation.ClientID%>').css('visibility', 'visible');
                    $('#<%=lblReasonValidation.ClientID%>').text('Please enter the reason for ' + actionName);
                    return false;
                }
            }

            if ($('#<%=btnDeny.ClientID%>').val() == "Deny") {
                if ($('#<%=lblReason.ClientID%>').css('visibility') == 'hidden') {
                    $('#<%=lblReason.ClientID%>').css('visibility', 'visible');
                    $('#<%=txtReason.ClientID%>').css('visibility', 'visible');
                    return false;
                }
                else if ($('#<%=txtReason.ClientID%>').val() == '') {
                    $('#<%=lblReasonValidation.ClientID%>').css('visibility', 'visible');
                    $('#<%=lblReasonValidation.ClientID%>').text('Please enter the reason for ' + actionName);
                    return false;
                }
            }

            return true;
        }

        $(function () {
            $("#<%=pnlPermanentAddressEdit.ClientID%>").change(function () {
                $("#<%=pnlPermanentAddressEdit.ClientID%>").data("changed", true);
            });

            $("#<%=pnlPresentAddressEdit.ClientID%>").change(function () {
                $("#<%=pnlPresentAddressEdit.ClientID%>").data("changed", true);
            });

        });

        function ValidatePage() {
            if (Page_ClientValidate() && ValidatePermanentAddressEdit() && ValidatePresentAddressEdit()) {
                return true;
            }
            else {
                return false;
            }
        }

        function ValidatePermanentAddressEdit() {
            if ($("#<%=pnlPermanentAddressEdit.ClientID%>").data("changed")) {

                if ($("[id*='ucPermanentAddress_FlupldElectricitybill']").val() == "") {
                    $("[id*='ucPermanentAddress_lblValidation']").css('visibility', 'visible');
                    return false;
                }
            }

            if ($("[id*='ucPermanentAddress_txtAddress']").val() != "") {
                if ($("[id*='ucPermanentAddress_txtPIN']").val() == "") {
                    $("[id*='ucPermanentAddress_lblPinValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblPinValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPermanentAddress_txtCity']").val() == "") {
                    $("[id*='ucPermanentAddress_lblCityValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblCityValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPermanentAddress_ddlStateName']").val() == 0 || $("[id*='ucPermanentAddress_ddlStateName']").val() == null) {
                    $("[id*='ucPermanentAddress_lblStateValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblStateValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPermanentAddress_ddlDistrictName']").val() == 0 || $("[id*='ucPermanentAddress_ddlStateName']").val() == null) {
                    $("[id*='ucPermanentAddress_lblDistrictValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPermanentAddress_lblDistrictValidation']").css('visibility', 'hidden');
            }
            return true;
        }

        function ValidatePresentAddressEdit() {
            if ($("#<%=pnlPresentAddressEdit.ClientID%>").data("changed")) {

                if ($("[id*='ucPresentAddress_FlupldElectricitybill']").val() == "") {
                    $("[id*='ucPresentAddress_lblValidation']").css('visibility', 'visible');
                    return false;
                }
            }
            if ($("[id*='ucPresentAddress_txtAddress']").val() != "") {
                if ($("[id*='ucPresentAddress_txtPIN']").val() == "") {
                    $("[id*='ucPresentAddress_lblPinValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPresentAddress_lblPinValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPresentAddress_txtCity']").val() == "") {
                    $("[id*='ucPresentAddress_lblCityValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPresentAddress_lblCityValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPresentAddress_ddlStateName']").val() == 0 || $("[id*='ucPresentAddress_ddlStateName']").val() == null) {
                    $("[id*='ucPresentAddress_lblStateValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPresentAddress_lblStateValidation']").css('visibility', 'hidden');
                if ($("[id*='ucPresentAddress_ddlDistrictName']").val() == 0 || $("[id*='ucPresentAddress_ddlStateName']").val() == null) {
                    $("[id*='ucPresentAddress_lblDistrictValidation']").css('visibility', 'visible');
                    return false;
                }
                $("[id*='ucPresentAddress_lblDistrictValidation']").css('visibility', 'hidden');
            }
            return true;
        }

    </script>
</asp:Content>
<asp:Content ID="maincontent" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <div class="mainContent">
            <asp:Panel ID="Panelnews" runat="server">
            </asp:Panel>
            <asp:Panel ID="pnlAdmin" runat="server">
                <asp:Panel ID="pnlTools" runat="server">
                    <asp:Button ID="btnViewAll" runat="server" Text="View All" OnClick="btnViewAll_Click" CssClass="button greenButton medium" />
                    <asp:Button ID="btnVoterCardRequest" Text="View Voter Card Requests" runat="server" CssClass="button greenButton medium"
                        OnClick="btnViewVoterCardRequest_Click" />
                </asp:Panel>
                <div class="form-content">
                    <asp:Panel ID="pnlFilter" runat="server" CssClass="filter" Visible="false">
                        <span style="float: left; margin-top: 3px">Filter(If none is checked, all will be displayed.):</span>
                        <asp:CheckBoxList ID="cblFilter" RepeatDirection="Horizontal" runat="server" AutoPostBack="true"
                            OnSelectedIndexChanged="cblFilter_SelectedIndexChanged">
                            <asp:ListItem Text="Approved" Value="Approved"></asp:ListItem>
                            <asp:ListItem Text="Deactivated" Value="Deactivated"></asp:ListItem>
                        </asp:CheckBoxList>
                    </asp:Panel>
                </div>
                <div class="form-content" style="float: left;">
                    <asp:GridView ID="gvVoterCard" runat="server" AllowPaging="true" AutoGenerateColumns="False"
                        CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                        EmptyDataText="No records found!" AllowSorting="true" OnSorting="gvVoterCard_Sorting"
                        OnPageIndexChanging="gvVoterCard_PageIndexChanging" OnRowCommand="gvVoterCard_RowCommand"
                        OnRowEditing="gvVoterCard_RowEditing" BorderWidth="2px">
                        <HeaderStyle VerticalAlign="Top" BackColor="#003366" ForeColor="White" />
                        <RowStyle BackColor="White" ForeColor="Black" />
                        <Columns>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:HiddenField ID="hdnVoterCardId" runat="server" Value='<%# Eval("VoterCardId") %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Voter Id" DataField="VoterId" SortExpression="VoterId" />
                            <asp:BoundField HeaderText="First Name" DataField="FirshtName" SortExpression="FirshtName" />
                            <asp:BoundField HeaderText="Middle Name" DataField="MiddleName" SortExpression="MiddleName" />
                            <asp:BoundField HeaderText="Last Name" DataField="LastName" SortExpression="LastName" />
                            <asp:BoundField HeaderText="IsApproved" DataField="IsApproved" />
                            <asp:TemplateField HeaderText="Action">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnEdit" CommandName="Edit" CommandArgument='<%# Container.DataItemIndex %>'
                                        runat="server">Edit</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </div>
            </asp:Panel>
            <div class="form-content">
                <asp:Panel ID="pnlDisplay" runat="server">
                    <asp:HiddenField ID="hdnVoterCardId" runat="server" />
                    <div class="form-content">
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblVoterId" runat="server" Text="Voter Id:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblVoterIdValue" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblFirstName" runat="server" Text="First Name:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblFirstNameValue" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblMiddleName" runat="server" Text="Middle Name:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblMiddleNameValue" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblLastName" runat="server" Text="Last Name:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblLastNameValue" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblAge" runat="server" Text="Age:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblAgeValue" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblSex" runat="server" Text="Sex:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblSexValue" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblDateofBirth" runat="server" Text="Date of Birth:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblDateofBirthValue" runat="server"></asp:Label>
                            </div>
                        </div>
                        <div class="form-fields clearfix">
                            <div class="fl txtrgt divsize1">
                                <asp:Label ID="lblAddress" runat="server" Text="Address:"></asp:Label>
                            </div>
                            <div class="fr txtlft divsize2">
                                <asp:Label ID="lblAddressValue" runat="server"></asp:Label>
                            </div>
                            <div class="form-fields clearfix">
                                <div class="fl txtrgt divsize1">
                                    <asp:Label ID="lblPIN" runat="server" Text="PIN:"></asp:Label>
                                </div>
                                <div class="fr txtlft divsize2">
                                    <asp:Label ID="lblPINValue" runat="server"></asp:Label>
                                </div>
                            </div>
                            <div class="form-fields clearfix">
                                <div class="fl txtrgt divsize1">
                                    <asp:Label ID="lblCity" runat="server" Text="City:"></asp:Label>
                                </div>
                                <div class="fr txtlft divsize2">
                                    <asp:Label ID="lblCityValue" runat="server"></asp:Label>
                                </div>
                            </div>
                            <div class="form-fields clearfix">
                                <div class="fl txtrgt divsize1">
                                    <asp:Label ID="lblStateName" runat="server" Text="State:"></asp:Label>
                                </div>
                                <div class="fr txtlft divsize2">
                                    <asp:Label ID="lblStateNameValue" runat="server"></asp:Label>
                                </div>
                            </div>
                            <div class="form-fields clearfix">
                                <div class="fl txtrgt divsize1">
                                    <asp:Label ID="lblDistrictName" runat="server" Text="District:"></asp:Label>
                                </div>
                                <div class="fr txtlft divsize2">
                                    <asp:Label ID="lblDistrictNameValue" runat="server"></asp:Label>
                                </div>
                            </div>
                            <div class="bottomButtons form-fields clearfix">
                                <asp:LinkButton ID="lbnViewElectricBillXerox" runat="server" OnClick="lbnViewElectricBillXerox_Click">View Electrical Bill Xerox</asp:LinkButton>
                            </div>
                        </div>
                    </div>
                </asp:Panel>
                <center>
                    <asp:Label ID="lblStatus" runat="server" BackColor="Yellow" ForeColor="DarkBlue"
                        Font-Bold="true"></asp:Label>
                </center>
                <div class="bottomButtons">
                    <asp:Button ID="btnApply" Text="Apply for Voter Card" runat="server" OnClick="btnApply_Click"
                        CssClass="button greenButton medium" Style="margin: 20px" Visible="false" />
                </div>
                <asp:Panel ID="pnlAdminActions" runat="server" Visible="false">
                    <div class="form-fields clearfix">
                        <div class="fl txtrgt divsize1 bottomButtons">
                            <asp:Button ID="btnApprove" runat="server" Text="Approve" OnClick="btnApprove_Click"
                                CssClass="button greenButton medium" />
                            <asp:Button ID="btnDeactivate" runat="server" Text="Deactivate" OnClientClick="return ReasonVisible('Deactivate');"
                                OnClick="btnDeactivate_Click" CssClass="button red medium" />
                            <asp:Button ID="btnDeny" runat="server" Text="Deny" OnClientClick="return ReasonVisible('Deny');"
                                OnClick="btnDeny_Click" CssClass="button red medium" />
                            <asp:Label ID="lblReason" Style="visibility: hidden;" runat="server" Text="Reason:"></asp:Label>
                        </div>
                        <div class="fr txtlft divsize2">
                            <asp:TextBox ID="txtReason" Style="visibility: hidden;" runat="server" TextMode="MultiLine"
                                Rows="5"></asp:TextBox>
                            <asp:Label ID="lblReasonValidation" Style="visibility: hidden;" runat="server" CssClass="redText"></asp:Label>
                        </div>
                    </div>
                </asp:Panel>
                <asp:Panel ID="pnlVoterCardRequest" Visible="false" runat="server">
                    If your address has been changed, please update it and submit the request.
                    <asp:Panel ID="pnlPermanentAddressEdit" runat="server">
                        <div class="SideText">
                            Permanet Address:</div>
                        <UC:AddressControl ID="ucPermanentAddress" runat="server" />
                    </asp:Panel>
                    <asp:Panel ID="pnlPresentAddressEdit" runat="server">
                        <div class="SideText">
                            Present Address:</div>
                        <UC:AddressControl ID="ucPresentAddress" runat="server" />
                    </asp:Panel>
                    <div class="bottomButtons form-fields clearfix">
                        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return ValidatePage()"
                            CssClass="button greenButton medium" OnClick="btnSubmit_Click" />
                    </div>
                </asp:Panel>
            </div>
        </div>
        <div class="Gadget">
            <UC:UserGadget ID="ucUserGadget" runat="server" />
        </div>
    </div>
</asp:Content>
